<template>
  <div class="app-container">
    <el-form :model="queryParams" size="mini" ref="queryForm" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="学号" prop="stuNo">
        <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请时间" prop="applyTime">
        <el-date-picker clearable v-model="queryParams.applyTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-input v-model="queryParams.grade" placeholder="请输入年级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input v-model="queryParams.major" placeholder="请输入专业" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="请假原因" prop="reason">
        <el-input v-model="queryParams.reason" placeholder="请输入请假原因" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="去向地址" prop="toAddr">
        <el-input v-model="queryParams.toAddr" placeholder="请输入去向地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="家长姓名" prop="parentName">
        <el-input v-model="queryParams.parentName" placeholder="请输入家长姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="本人承诺" prop="commit">
        <el-input v-model="queryParams.commit" placeholder="请输入本人承诺" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="本人联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入本人联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="去向地联络人" prop="toPeople">
        <el-input v-model="queryParams.toPeople" placeholder="请输入去向地联络人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="去向地联系电话" prop="toPhone">
        <el-input v-model="queryParams.toPhone" placeholder="请输入去向地联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员签字" prop="fdySign">
        <el-input v-model="queryParams.fdySign" placeholder="请输入辅导员签字" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员工号" prop="fdyNo">
        <el-input v-model="queryParams.fdyNo" placeholder="请输入辅导员工号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="辅导员审核时间" prop="fdyTime">
        <el-date-picker clearable v-model="queryParams.fdyTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择辅导员审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="学院领导签字盖章" prop="deptSign">
        <el-input v-model="queryParams.deptSign" placeholder="请输入学院领导签字盖章" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学院领导时间" prop="deptNo">
        <el-input v-model="queryParams.deptNo" placeholder="请输入学院领导时间" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学院领导审核时间" prop="deptTime">
        <el-date-picker clearable v-model="queryParams.deptTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择学院领导审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="销假时间" prop="takingTime">
        <el-date-picker clearable v-model="queryParams.takingTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择销假时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="销假签名" prop="takingSign">
        <el-input v-model="queryParams.takingSign" placeholder="请输入销假签名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="销假附件" prop="takingMaterial">
        <el-input v-model="queryParams.takingMaterial" placeholder="请输入销假附件" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['leave:apply:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['leave:apply:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['leave:apply:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['leave:apply:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="leaveApplyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="#" align="center" prop="id" />
      <el-table-column label="学号" align="center" prop="stuNo" />
      <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center" prop="applyStatus" />
      <el-table-column label="年级" align="center" prop="grade" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="请假原因" align="center" prop="reason" />
      <el-table-column label="开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="去向地址" align="center" prop="toAddr" />
      <el-table-column label="家长姓名" align="center" prop="parentName" />
      <el-table-column label="本人承诺" align="center" prop="commit" />
      <el-table-column label="本人联系电话" align="center" prop="phone" />
      <el-table-column label="去向地联络人" align="center" prop="toPeople" />
      <el-table-column label="去向地联系电话" align="center" prop="toPhone" />
      <el-table-column label="辅导员签字" align="center" prop="fdySign" />
      <el-table-column label="辅导员工号" align="center" prop="fdyNo" />
      <el-table-column label="辅导员审核时间" align="center" prop="fdyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fdyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学院领导签字盖章" align="center" prop="deptSign" />
      <el-table-column label="学院领导时间" align="center" prop="deptNo" />
      <el-table-column label="学院领导审核时间" align="center" prop="deptTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deptTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="销假时间" align="center" prop="takingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="销假签名" align="center" prop="takingSign" />
      <el-table-column label="销假附件" align="center" prop="takingMaterial" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['leave:apply:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['leave:apply:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改请假申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="学号" prop="stuNo">
          <el-input v-model="form.stuNo" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="申请时间" prop="applyTime">
          <el-date-picker clearable v-model="form.applyTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入年级" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="请假原因" prop="reason">
          <el-input v-model="form.reason" placeholder="请输入请假原因" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable v-model="form.startTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="去向地址" prop="toAddr">
          <el-input v-model="form.toAddr" placeholder="请输入去向地址" />
        </el-form-item>
        <el-form-item label="本人承诺" prop="commit">
          <el-input v-model="form.commit" placeholder="请输入本人承诺" />
        </el-form-item>
        <el-form-item label="本人联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入本人联系电话" />
        </el-form-item>
        <el-form-item label="去向地联络人" prop="toPeople">
          <el-input v-model="form.toPeople" placeholder="请输入去向地联络人" />
        </el-form-item>
        <el-form-item label="去向地联系电话" prop="toPhone">
          <el-input v-model="form.toPhone" placeholder="请输入去向地联系电话" />
        </el-form-item>
        <el-form-item label="辅导员签字" prop="fdySign">
          <el-input v-model="form.fdySign" placeholder="请输入辅导员签字" />
        </el-form-item>
        <el-form-item label="辅导员工号" prop="fdyNo">
          <el-input v-model="form.fdyNo" placeholder="请输入辅导员工号" />
        </el-form-item>
        <el-form-item label="辅导员审核时间" prop="fdyTime">
          <el-date-picker clearable v-model="form.fdyTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择辅导员审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学院领导签字盖章" prop="deptSign">
          <el-input v-model="form.deptSign" placeholder="请输入学院领导签字盖章" />
        </el-form-item>
        <el-form-item label="学院领导时间" prop="deptNo">
          <el-input v-model="form.deptNo" placeholder="请输入学院领导时间" />
        </el-form-item>
        <el-form-item label="学院领导审核时间" prop="deptTime">
          <el-date-picker clearable v-model="form.deptTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择学院领导审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销假时间" prop="takingTime">
          <el-date-picker clearable v-model="form.takingTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择销假时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销假签名" prop="takingSign">
          <el-input v-model="form.takingSign" placeholder="请输入销假签名" />
        </el-form-item>
        <el-form-item label="销假附件" prop="takingMaterial">
          <el-input v-model="form.takingMaterial" placeholder="请输入销假附件" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLeaveApply, getLeaveApply, delLeaveApply, addLeaveApply, updateLeaveApply } from "@/api/leave/leaveApply";

export default {
  name: "LeaveApply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假申请表格数据
      leaveApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuNo: null,
        applyTime: null,
        applyStatus: null,
        grade: null,
        major: null,
        reason: null,
        startTime: null,
        endTime: null,
        toAddr: null,
        parentName: null,
        commit: null,
        phone: null,
        toPeople: null,
        toPhone: null,
        fdySign: null,
        fdyNo: null,
        fdyTime: null,
        deptSign: null,
        deptNo: null,
        deptTime: null,
        takingTime: null,
        takingSign: null,
        takingMaterial: null,
        orderByColumn: "id",
        isAsc: "desc"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询请假申请列表 */
    getList() {
      this.loading = true;
      listLeaveApply(this.queryParams).then(response => {
        this.leaveApplyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuNo: null,
        applyTime: null,
        applyStatus: null,
        grade: null,
        major: null,
        reason: null,
        startTime: null,
        endTime: null,
        toAddr: null,
        parentName: null,
        commit: null,
        phone: null,
        toPeople: null,
        toPhone: null,
        fdySign: null,
        fdyNo: null,
        fdyTime: null,
        deptSign: null,
        deptNo: null,
        deptTime: null,
        takingTime: null,
        takingSign: null,
        takingMaterial: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加请假申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLeaveApply(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改请假申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLeaveApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLeaveApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除请假申请编号为"' + ids + '"的数据项？').then(function () {
        return delLeaveApply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('leave/apply/export', {
        ...this.queryParams
      }, `leaveApply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
